package org.ueg.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.ueg.interfaces.IDao;
import org.ueg.model.Assento;



public class DaoAssento extends HibernateDao<Assento> implements IDao<Assento>{

	public DaoAssento(Class classe) {
		super(classe);
	}

	@Override
	public void salva(Assento object) throws Exception {
		Session session = super.getSession();
		Transaction transaction = session.beginTransaction();
		try {
			session.saveOrUpdate(object);
			transaction.commit();
		} catch (Exception e) {
			// TODO: handle exception
			transaction.rollback();
			throw e;
		} finally {
			session.close();
		}
		
	}

	@Override
	public void deleta(Assento object) throws Exception {
		Session session = super.getSession();
		Transaction transaction = session.beginTransaction();
		try {
			session.delete(object);
			transaction.commit();
		} catch (Exception e) {
		// TODO: handle exception
			transaction.rollback();
		throw e;
		} finally {
			session.close();
		}	// TODO Auto-generated method stub
		
	}

	@Override
	public List<Assento> listar() throws Exception {
		// TODO Auto-generated method stub
				Session session = super.getSession();
				try{
					Query query = session.createQuery("From Assento");
					return (List<Assento>) query.list();
				}catch(Exception e){
					throw e;
				}finally{
					session.close();
				}
	}


	@Override
	public void altera(Assento object) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Assento getById(Assento object) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
